package com.chushouya.controller.product.admin;

import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.general.framework.web.annotations.RepeatSubmit;
import com.chushouya.product.dto.admin.product.evaluate.SkuEvaluateItemValueAddDTO;
import com.chushouya.product.dto.admin.product.evaluate.SkuEvaluateItemValueEditDTO;
import com.chushouya.product.dto.admin.product.evaluate.SkuItemDTO;
import com.chushouya.product.dto.admin.skuevaluate.SkuEvaluateItemAddSingleDTO;
import com.chushouya.product.dto.admin.skuevaluate.SkuEvaluateItemValueDetailDTO;
import com.chushouya.product.service.admin.SkuEvaluateItemValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = ServiceType.PLATFORM + "SKU估价项目选项管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/skuEvaluateItemValue")
public class SkuEvaluateItemValueController {

    @Resource
    private SkuEvaluateItemValueService skuEvaluateItemValueService;

    @ApiOperation("添加SKU估价项目选项")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public Response<Boolean> addSkuEvaluateItemValue( @Validated @RequestBody SkuEvaluateItemValueAddDTO addDTO) {
        return Response.success(skuEvaluateItemValueService.addSkuEvaluateItemValue(addDTO));
    }

    @ApiOperation("根据产品ID获取SKU估价项目选项列表")
    @GetMapping("/combineList")
    public Response<List<SkuItemDTO>> list(@RequestParam Long productId) {
        List<SkuItemDTO> list = skuEvaluateItemValueService.getSkuItemsByProductId(productId);
        return Response.success(list);
    }

    @ApiOperation("获取SKU估价项目选项详情")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "skuItemValueId", value = "SKU估价项目选项ID", required = true)
    })
    public Response<SkuEvaluateItemValueDetailDTO> getDetail(@RequestParam Long skuItemValueId) {
        return Response.success(skuEvaluateItemValueService.getSkuEvaluateItemValueDetail(skuItemValueId));
    }

    @ApiOperation("修改SKU估价项目选项价格")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/updatePrice")
    @RepeatSubmit
    public Response<Boolean> updateSkuEvaluateItemValuePrice(@Validated @RequestBody SkuEvaluateItemValueEditDTO editDTO) {
        return Response.success(skuEvaluateItemValueService.updateSkuEvaluateItemValuePrice(editDTO));
    }

    @ApiOperation("根据skuItemId和productId删除整个估价项目")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/deleteBySkuItemId")
    @RepeatSubmit
    @ApiImplicitParams({
            @ApiImplicitParam(name = "skuItemId", value = "SKU估价项目ID", required = true),
            @ApiImplicitParam(name = "productId", value = "商品ID", required = true)
    })
    public Response<Boolean> deleteBySkuItemId(@RequestParam Long skuItemId, @RequestParam Long productId) {
        return Response.success(skuEvaluateItemValueService.deleteSkuEvaluateItemBySkuItemId(skuItemId, productId));
    }

    @ApiOperation("根据skuItemValueId删除对应的估价记录")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/deleteById")
    @RepeatSubmit
    @ApiImplicitParams({
            @ApiImplicitParam(name = "skuItemValueId", value = "SKU估价项目选项ID", required = true)
    })
    public Response<Boolean> deleteById(@RequestParam Long skuItemValueId) {
        return Response.success(skuEvaluateItemValueService.deleteSkuEvaluateItemValueById(skuItemValueId));
    }

    @ApiOperation("编辑SKU估价项目选项")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @RepeatSubmit
    public Response<Boolean> edit(@Validated @RequestBody SkuEvaluateItemValueEditDTO editDTO) {
        return Response.success(skuEvaluateItemValueService.editSkuEvaluateItemValue(editDTO));
    }

    @ApiOperation("根据估价项目ID添加单个SKU估价项目")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/addSingle")
    @RepeatSubmit
    public Response<Boolean> addSingle(@Validated @RequestBody SkuEvaluateItemAddSingleDTO addSingleDTO) {
        return Response.success(skuEvaluateItemValueService.addSkuEvaluateItemSingle(addSingleDTO));
    }
}
